//
// Created by delin10 on 2020/5/4.
//
#include "stdio.h"
#include "stdlib.h"
#include "debug.h"
#include "stdarg.h"
#include "string_utils.h"

void d_log_err(char* fmt, ...) {
    va_list list;
    //1. 先获取格式化后字符串的长度
    va_start(list, fmt);
    int size = vsnprintf(NULL, 0, fmt, list);
    va_end(list);
    size++;

    //2. 复位va_list，将格式化字符串写入到buf
    va_start(list, fmt);
    char *buf = (char *)malloc(size);
    vsnprintf(buf, size, fmt, list);
    va_end(list);
    fprintf(stderr, "%s", buf);
    free(buf);
}